package com.iot.service;

import com.iot.mapper.DTdevice_protocolMapper;
import com.iot.mapper.Tdevice_protocolMapper;
import com.iot.pojo.MTdevice_protocol;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class Tdevice_protocolServiceImpl  implements Tdevice_protocolService {
    @Autowired
    private Tdevice_protocolMapper mapper;
    @Autowired
    private DTdevice_protocolMapper dmapper;
    @Override
    public int getRecordCount(String sWhere) {
        return mapper.getRecordCount(sWhere);
    }

    @Override
    public int insert(MTdevice_protocol mTdevice_protocol) throws Exception {
        int count = 0;
        count = getRecordCount(" AND SNAME='" + mTdevice_protocol.getSNAME() + "'");
        if (count > 0)
            throw new Exception("该名称已存在");
        return mapper.insert(mTdevice_protocol);
    }

    @Override
    public void update(MTdevice_protocol mTdevice_protocol) throws Exception {
        int count = 0;
        count = getRecordCount(" AND SNAME='" + mTdevice_protocol.getSNAME() + "' AND PROTOCOL_ID!=" + mTdevice_protocol.getPROTOCOL_ID() + "");
        if (count > 0)
            throw new Exception("该名称已存在");
        mapper.update(mTdevice_protocol);
    }

    @Override
    public void deleteById(int id) {
        mapper.deleteById(id);
    }

    @Override
    public MTdevice_protocol single(Integer id) {
        return mapper.single(id);
    }

    @Override
    public List<MTdevice_protocol> fetch(String sWhere) {
        return mapper.fetch(sWhere);
    }

    @Override
    public List<MTdevice_protocol> fetchByPage(Map<String, Object> map) {
        return dmapper.fetchByPage(map);
    }


}
